function [lc,lp] = blslambda(so,x,r,t,sig,q)  
%BLSLAMBDA Black-Scholes elasticity.  
%   [LC,LP] = BLSLAMBDA(SO,X,R,T,SIG,Q) returns the elasticity of an option. 
%   Elasticity (the leverage of an option position) measures the percent change 
%   in an option price per one percent change in the underlying stock price.  
%   SO is the current stock price, X is the exercise price, R is the risk-free
%   interest rate, T is the time to maturity of the option in years, SIG is the   
%   standard deviation of the annualized continuously compounded rate of return 
%   of the stock (also known as the volatility), and Q is the dividend rate.
%   The default Q is 0.  LC is the call option elasticity or leverage factor 
%   and LP is the put option elasticity or leverage factor. 
%        
%   Note: 
%     This function uses normcdf, the normal cumulative distribution  
%     function in the Statistics Toolbox.  
%  
%   For example, [c,p] = blslambda(50,50,.12,.25,.3) returns    
%   c = 8.1274 and p = -8.6466.  
%  
%   See also BLSPRICE, BLSDELTA, BLSGAMMA, BLSRHO, BLSTHETA, BLSVEGA.  
%  
%   Reference: Advanced Options Trading, Daigler, Chapter 4  
  
%       Copyright 1995-2006 The MathWorks, Inc.
%       $Revision: 1.7.2.4 $   $Date: 2009/04/15 23:07:19 $  
  
if nargin < 5  
  error('finance:blslambda:missingInputs',sprintf('Missing one of SO, X, R, T, and SIG.'))  
end  
if any(so <= 0 | x <= 0 | r < 0 | t <=0 | sig < 0)  
  error('finance:blslambda:invalidInputs',sprintf('Enter SO, X, and T > 0. Enter R and S >= 0.'))  
end  
if nargin < 6  
  q = zeros(size(so));  
end  
  
message = blscheck('blslambda', so, x, r, t, sig, q);
error(message);


% Perform scalar expansion & guarantee conforming arrays.
try
    [so, x, r, t, sig, q] = finargsz('scalar', so, x, r, t, sig, q);
catch
    error('Finance:blslambda:InconsistentDimensions', ...
        'Inputs must be scalars or conforming matrices.')
end

% blspriceeng works with columns. Get sizes, turn to columns, run engine,
% and finally turn to arrays again:
[m, n] = size(so);

% Double up on fcn calls since blsprice calculates both calls and puts. Do
% this only if nargout>1

NumOpt = numel(so);
callSpec = {'call'};
callSpec = callSpec(ones(NumOpt,1));
putSpec = {};
if(nargout)>1
    putSpec = {'put'};
    putSpec = putSpec(ones(NumOpt,1));
    
    % double up the rest of the input args
    [so, x, r, t, sig, q] = deal([so(:);so(:)], [x(:);x(:)], [r(:);r(:)], ...
         [t(:);t(:)], [sig(:);sig(:)], [q(:);q(:)]);
end

OptSpec = [callSpec;putSpec];
OutSpec = {'lambda'};

% call eng fuction
lambda = blspriceeng(OutSpec, OptSpec, so, x, r, t, sig, q);

% Now separate calls from puts
lc=reshape(lambda{1}(1:NumOpt), m, n);
if(nargout>1)
    lp = reshape(lambda{1}(NumOpt+1:end), m, n);
end  
